<?php
    /******************************************************************************
     *    Copyright ZhangYue
     * Author:                Quinn Xu
     * Description:           查看属性类表,配置属性值
     * Want argument:         
     * Output:                
     * Create Date:           2012-12-18
     *****************************************************************************/
    include_once 'config.inc.php';
    include_once DATACLASS.'peizhi.class.php';
    include_once DATACLASS.'peizhiguanli.class.php';
    include_once DATACLASS . 'chengji.class.php';
    include_once DATACLASS . 'chengjiguanli.class.php';
    $chengji = new chengji();
    $chengjiguanli = new chengjiguanli();
    $peizhi = new peizhi();
    $peizhiguanli = new peizhiguanli();
    
    //获取班级列表
    $banjiliebiao = $chengjiguanli->huoqubanjiliebiao();
    $banjiliebiaoStr = '';
    foreach($banjiliebiao as $key=>$value)
    {
        $banjiliebiaoStr .= $value['banji'] . ',';
    }
    $banjiliebiaoLen = strlen($banjiliebiaoStr);
    $banjiliebiaoStr = substr($banjiliebiaoStr, 0,$banjiliebiaoLen-1);
    $peizhi->setShuxingming('banjiliebiao');
    $peizhi->setShuxingzhi($banjiliebiaoStr);
    $peizhiguanli->tongguoshuxingmingpeizhishuxingzhi($peizhi);//同步成绩表中班级列表
    
    //获取总人数
    $zongrenshu = $chengjiguanli->huoquzongrenshu();
    $zongrenshu = $zongrenshu[0]['zongrenshu'];
    $peizhi->setShuxingming('zongrenshu');
    $peizhi->setShuxingzhi($zongrenshu);
    $peizhiguanli->tongguoshuxingmingpeizhishuxingzhi($peizhi);//同步成绩表中总人数
    
    //获取配置表中数据
    $result = $peizhiguanli->huoqupeizhiliebiao();
    
    //获取各层次占比
    $cengci = array('A层次占比','B层次占比','C层次占比','D层次占比');
    $zuihoumingcishuzu = array('A层次最后名次','B层次最后名次','C层次最后名次','D层次最后名次');
    $cengcizhanbi = array();//各层次比例及名次上限
    foreach($cengci as $key=>$value)
    {
        $peizhi->setShuxingming($value);
        $temp = $peizhiguanli->tongguoshuxingminghuoqushuxingzhi($peizhi);//获取层次占比
        $cengcizhanbi[$value]['bili'] = $temp[0]['shuxingzhi'];
        $cengcizhanbi[$value]['mingci'] = round($zongrenshu * $cengcizhanbi[$value]['bili']);//计算层次人数
        if($cengcizhanbi[$value]['mingci'])
        {
            $chengji->setJiezhimingci($cengcizhanbi[$value]['mingci']-1);//层次人数-1 SQL中+1
            $zuihoumingci = $chengjiguanli->huoquzuihoumingci($chengji);
            $zuihoumingci = $zuihoumingci[0]['nianjimingci'];
            $peizhi->setShuxingming($zuihoumingcishuzu[$key]);
            $peizhi->setShuxingzhi($zuihoumingci);
            $peizhiguanli->tongguoshuxingmingpeizhishuxingzhi($peizhi);//将最后名次写入数据表
        }
    }
    //获取各层次最后名次
//     $chengjiguanli;
    //获取配置信息
    $smarty->assign('result',$result);
    $smarty->display('peizhi.html');
?>